home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / one2many.zip / ONE2MANY.PAS < prev    next >
Pascal/Delphi Source File  |  1991-08-07  |  9KB  |  360 lines

  1. PROGRAM OneToMany;
  2.  
  3. {
  4.    One2Many - V02.00B
  5.    (C)opyright 1991 - Caboose Software Engineering
  6.  
  7.    This program is meant to demonstrate how one might browse a 1:M file
  8.    using the extremely powerful Browse routine in Topaz.
  9.  
  10.    It also is meant to demonstrate some of the more advanced, and possibly
  11.    confusing, Topaz features such as configurable and overlayed browsing,
  12.    indexing, relational technology and filter conditions.  I apologize if
  13.    the source code is a confusing in any way.  A slight background in
  14.    relational technology may be required before, or obtained from, reading
  15.    this code.
  16.  
  17.    Note that I had some problems in implementation.  Some things in the
  18.    Topaz manual are not as clear as they should be (what does PushBrowse
  19.    actually push? etc.) and the demonstrations included with Topaz did
  20.    little to show me the way.  Hooray for their superior technical
  21.    support!
  22.    
  23.    This code is hereby donated to the Public Domain.  May the tradition of
  24.    our computing pioneers live on!  Let the code be distributed freely!
  25.    If some techniques are of value, a comment in your source code or
  26.    documentation would certainly make my day.
  27.  
  28.    Written by Barry Smith.
  29.  
  30.    Many thanks to Richard Matzinger of Software Science Inc., John Graves of
  31.    NetComm Inc. and Purdue University CPT.
  32.  
  33.    If you are interested in starting a Topaz user group or newsletter please
  34.    write me at the following address.
  35.  
  36.    Caboose Software Engineering
  37.    2921 Bluff Point Lane
  38.    Silver Spring, MD   20906
  39.    301/460-1437
  40. }
  41.  
  42. USES
  43.    DBF4,
  44.    Browse4,
  45.    Index4,
  46.    TimeDate,
  47.    VidPop,
  48.    TZCommon,
  49.    SayGet4,
  50.    Crt;
  51.  
  52. TYPE
  53.    ACCOUNT_Record = RECORD
  54.       Deleted    : BOOLEAN;
  55.       _UID       : STRING[  5];
  56.       _AMOUNT    : LONGINT;        { width =   5}
  57.       _TRANTYPE  : STRING[  1];
  58.       _TRANSDATE : STRING[ 10]
  59.    End;
  60.  
  61.    {
  62.       _TRANTYPE = 1 (Total),
  63.                   2 (Deposit),
  64.                   3 (Withdrawal),
  65.                   4 (Open Account)
  66.    }
  67.  
  68.    CUSTOMER_Record = RECORD
  69.       Deleted : BOOLEAN;
  70.       _NAME   : STRING[ 20];
  71.       _UID    : STRING[  5];
  72.    End;
  73.  
  74. VAR
  75.    CUSTOMER           : CUSTOMER_record;
  76.    SAVINGS,
  77.    CHECKING,
  78.    TempRec            : ACCOUNT_record;
  79.    Done               : BOOLEAN;
  80.    CurrentAccountFile : BYTE;
  81.  
  82. {$F+}
  83. PROCEDURE DoTone;
  84.  
  85. BEGIN
  86.    Sound(500);
  87.    Delay(25);
  88.    NoSound
  89. END;
  90.  
  91. FUNCTION Center ( S          : STRING;
  92.                   LineLength : BYTE    ) : STRING;
  93.  
  94. VAR
  95.    I : INTEGER;
  96.    T : STRING;
  97.  
  98. BEGIN
  99.    T := '';
  100.    For I := 1 To ((LineLength Div 2) - (Length(S) Div 2)) DO
  101.       T := T + ' ';
  102.    Center := T + S
  103. END;
  104.  
  105. PROCEDURE InitTempRec;
  106.  
  107. BEGIN
  108.    CASE CurrentAccountFile Of
  109.       1 : TempRec := SAVINGS;
  110.       2 : TempRec := CHECKING
  111.    END;
  112. END;
  113.  
  114. PROCEDURE ClearScreen ( C : Char );
  115.  
  116. VAR
  117.    S : STRING;
  118.    I : INTEGER;
  119.  
  120. BEGIN
  121.    S := '';
  122.    FOR I := 1 TO Lo(WindMax) + 1 DO
  123.       S := S + C;
  124.    GotoXY(1, 1);
  125.    FOR I := 1 TO Hi(WindMax) + 1 DO
  126.       Write(S)
  127. END;
  128.  
  129. PROCEDURE InitializeMainBrowse; Forward;
  130.  
  131. PROCEDURE CustomerBrowse;
  132.  
  133. BEGIN
  134.    InitTempRec;
  135.    WITH DataDefinition^ DO
  136.       BEGIN
  137.          CASE Column Of
  138.              1 : BEGIN
  139.                     Prompt := 'NAME';
  140.                     VirtualField := CUSTOMER._NAME
  141.                  END;
  142.              2 : BEGIN
  143.                     Prompt := 'BALANCE';
  144.                     VirtualField := SInteger(TempRec._AMOUNT, 5)
  145.                  END
  146.          END
  147.       END
  148. END;
  149.  
  150. PROCEDURE AccountBrowse;
  151.  
  152. BEGIN
  153.    InitTempRec;
  154.    WITH DataDefinition^ DO
  155.       BEGIN
  156.          CASE Column OF
  157.              1 : BEGIN
  158.                     Prompt := 'TRANSACTION';
  159.                     CASE (TempRec._TRANTYPE[1]) OF
  160.                        '1' : VirtualField := 'TOTAL     ';
  161.                        '2' : VirtualField := 'DEPOSIT   ';
  162.                        '3' : VirtualField := 'WITHDRAWAL';
  163.                        '4' : VirtualField := 'OPEN ACCT '
  164.                     END
  165.                  END;
  166.              2 : BEGIN
  167.                     Prompt := 'DATE';
  168.                     IF TempRec._TRANTYPE[1] = '1'
  169.                        THEN
  170.                           VirtualField := SystemDate
  171.                        ELSE
  172.                           VirtualField := TempRec._TRANSDATE
  173.                  END;
  174.              3 : BEGIN
  175.                     Prompt := 'AMOUNT';
  176.                     VirtualField := SInteger(TempRec._AMOUNT, 5)
  177.                  END
  178.          END
  179.       END
  180. END;
  181.  
  182. FUNCTION SavingsKey : STRING;
  183.  
  184. BEGIN
  185.    SavingsKey := SAVINGS._UID + AnsiDate(SAVINGS._TRANSDATE)
  186. END;
  187.  
  188. FUNCTION CheckingKey : STRING;
  189.  
  190. BEGIN
  191.    CheckingKey := CHECKING._UID + AnsiDate(CHECKING._TRANSDATE)
  192. END;
  193.  
  194. FUNCTION CustomerKey : STRING;
  195.  
  196. BEGIN
  197.    CustomerKey := CUSTOMER._NAME
  198. END;
  199.  
  200. PROCEDURE RelateFiles;
  201.  
  202. BEGIN
  203.    Select(CurrentAccountFile + 1);
  204.    Find(CUSTOMER._UID);
  205.    Select(1)
  206. END;
  207.  
  208. FUNCTION FilterFunction : BOOLEAN;
  209.  
  210. BEGIN
  211.    InitTempRec;
  212.    Select(CurrentAccountFile + 1);
  213.    Find(CUSTOMER._UID);
  214.    InitTempRec;
  215.    FilterFunction := (CUSTOMER._UID = TempRec._UID);
  216.    Select(1)
  217. END;
  218.  
  219. FUNCTION AccountBrowseTitle ( AccountSelected : BYTE ) : STRING;
  220.  
  221. BEGIN
  222.    CASE AccountSelected OF
  223.       1 : AccountBrowseTitle := 'Savings';
  224.       2 : AccountBrowseTitle := 'Checking'
  225.    END
  226. END;
  227.  
  228. FUNCTION OnlyThese : BOOLEAN;
  229.  
  230. BEGIN
  231.    InitTempRec;
  232.    OnlyThese := (TempRec._UID = CUSTOMER._UID)
  233. END;
  234.  
  235. PROCEDURE ZoomBrowse;
  236.  
  237. BEGIN
  238.    Case LastKey Of
  239.       Chr(Ord(F8 ) + 128) :
  240.          BEGIN
  241.             IF CurrentAccountFile = 1
  242.                THEN 
  243.                   CurrentAccountFile := 2
  244.                ELSE
  245.                   CurrentAccountFile := 1;
  246.             DOTone;
  247.             InitializeMainBrowse;
  248.             ExitBrowse := TRUE
  249.          END;
  250.       Chr(Ord(F9 ) + 128) :
  251.          BEGIN
  252.             PushBrowse;
  253.             Select(CurrentAccountFile + 1);
  254.             Set_DataDefinition_To(@AccountBrowse);
  255.             Set_While_To(@OnlyThese);
  256.             PushWindow(22, 7, 59, 19);
  257.             Set_BrowseWindow_To(22, 7, 57, 17,
  258.                DoubleTopSingleSide + Explode + Shadow, Trim(CUSTOMER._NAME));
  259.             GotoXY(1, Hi(WindMax) + 1);
  260.             ClrEOL;
  261.             AT(1, Hi(WindMax) + 1, 
  262.                Center('ESC - CUSTOMERS ║ ' + 
  263.                   #27#24#25#26' - MOVE CURSOR', 80));
  264.             Set_Browse_Calc_To(NIL);
  265.             BrowseExitKeys := [#27];
  266.             WatchKeys := [];
  267.             Browse('PLAIN');
  268.          
  269.             PopBrowse;
  270.             Set_While_To(NIL);
  271.             Select(1);
  272.             InitializeMainBrowse;
  273.             ExitBrowse := TRUE;
  274.             PopWindow
  275.  
  276.             {
  277.                We have to ExitBrowse because PopBrowse WILL NOT restore the
  278.                browse screen to it's previous state.  We also have to push a
  279.                Window since the pop does not remove the new browse!
  280.             }
  281.  
  282.          END;
  283.       Chr(Ord(F10) + 128) :
  284.          BEGIN
  285.             Done := TRUE;
  286.             ExitBrowse := TRUE
  287.          END
  288.    END;
  289. END;
  290.  
  291. PROCEDURE InitializeMainBrowse;
  292.  
  293. BEGIN
  294.    Set_DataDefinition_To(@CUSTOMERBrowse);
  295.    Set_BrowseWindow_To(20, 5, 55, 15, DoubleTopSingleSide + Shadow,
  296.       'Topaz S & L - ' + AccountBrowseTitle(CurrentAccountFile));
  297.    Set_Browse_Calc_To(@ZoomBrowse);
  298.    BrowseExitKeys := [];
  299.    WatchKeys := [ Chr(Ord(F8 ) + 128),
  300.                   Chr(Ord(F9 ) + 128),
  301.                   Chr(Ord(F10) + 128)  ];
  302.    GotoXy(1, Hi(WindMax) + 1);
  303.    ClrEOL;
  304.    AT(1, Hi(WindMax) + 1, 
  305.       Center('F8 - SWITCH FILES ║ F9 - TRANSACTIONS ║ F10 - QUIT ║ ' +
  306.       #27#24#25#26' - MOVE CURSOR', 80));
  307. END;
  308.  
  309. PROCEDURE OpenFiles;
  310.  
  311. BEGIN
  312.    Select(1);
  313.    USE('CUSTOMER', @CUSTOMER, SizeOf(CUSTOMER));
  314.    MakeIndex(@CustomerKey, 'CUSTOMER.IND');
  315.    SET_INDEX_TO(@CustomerKey, 'CUSTOMER', 1);
  316.  
  317.    Select(2);
  318.    USE('SAVINGS', @SAVINGS, SizeOf(SAVINGS));
  319.    MakeIndex(@SavingsKey, 'SAVINGS.IND');
  320.    SET_INDEX_TO(@SavingsKey, 'SAVINGS', 1);
  321.    
  322.    Select(3